// 常量定义，通常可以放到一个单独的文件里面
export const INCREMENT = "increment"
export const DECREMENT = "decrement"
export const UPDATEUSERS = "updateUsers"
export const ASYNC_GETUSERS = "async_getUsers"


// 同步 action 定义，可以拆分到独立的功能文件中
export const increment = (payload = 1) => {
    return {
        type: INCREMENT,
        payload
    }
}
export const decrement = (payload = 2) => {
    return {
        type: DECREMENT, 
        payload
    }
}

export const updateUsers = (users = []) => {
    return {
        type: UPDATEUSERS, 
        users
    }
}

// 异步 action，必须配合中间件使用；自定义中间件
export const async_decrement = (payload = 2) => {
    return dispatch => {
        setTimeout(() => {
            dispatch(decrement(payload))
        }, 2000)
    }
}

// 异步 action，使用 redux-saga 示例
export const async_getUsers = (url) => {
    return {
        type: ASYNC_GETUSERS,
        url
    }
}